package com.npf.imgserver.controller.http;

import com.npf.imgserver.aspect.RateLimitAspect;
import com.npf.imgserver.common.base.ResultBase;
import com.npf.imgserver.common.enums.ResultCodeEnum;
import com.npf.imgserver.service.api.ImgInfoService;
import com.npf.imgserver.vo.ImgRequestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IDEA
 * author: NiPengFei
 * Date:18/9/22
 * Time:下午11:59
 */
@Api(value = "/imgUpLoad", tags = "图片上传接口")
@RestController
@RequestMapping("/imgUpLoad")
public class ImgHttpServer {

    public static final Logger logger = LoggerFactory.getLogger(ImgHttpServer.class);

    @Autowired
    private ImgInfoService imgInfoService;

    /**
     * Base64格式图片上传接口
     *
     * @param requestVo
     * @return
     */
    @RateLimitAspect
    @PostMapping("/Base64")
    @ApiOperation(value = "Base64格式图片上传接口", notes = "Base64格式图片上传接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appKey", value = "接入商秘钥", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "imgBase64", value = "Base64格式图片信息", required = true, paramType = "query", dataType = "String"),
    })
    public ResultBase imgBase64UpLoad(@RequestBody ImgRequestVo requestVo) {
        System.out.println("-------------进入接口-------------");
        ResultBase resultBase = null;
        try {
            resultBase=imgInfoService.imgBase64UpLoad(requestVo);
        } catch (Exception e) {
            logger.error("Base64格式图片上传失败", e);
            resultBase=new ResultBase(ResultCodeEnum.ERROR_SERVER);
        }
        System.out.println("-------------处理完成-------------");
        return resultBase;
    }

}
